package com.eastmoney.gamecode.vo;

import com.eastmoney.gamecode.constant.GameConstants;
import lombok.Data;

/**
 * TODO
 *
 * @author Liang Desheng
 * @version 1.0
 * @since 2023/10/10 23:19
 **/
@Data
public class Rect {
    protected int x;
    protected int y;
    protected int width;
    protected int height;

    public Loc toLoc() {
        return new Loc(x / GameConstants.DOWNSAMPLING, y / GameConstants.DOWNSAMPLING);
    }

    /**
     * 是否在毒圈内
     *
     * @param safeArea
     * @return
     */
    public boolean isInPoisonCircle(SafeAreaStateVo safeArea) {
        return !isInSafeArea(safeArea);
    }

    /**
     * 是否在安全区
     *
     * @param safeArea
     * @return
     */
    public boolean isInSafeArea(SafeAreaStateVo safeArea) {
        // 获取安全区域的圆心位置和半径
        int safeX = safeArea.getX();
        int safeY = safeArea.getY();
        int safeRadius = safeArea.getR();

        // 计算坦克的位置和安全区域圆心的距离
        double distance = Math.sqrt((x - safeX) * ((double)x - safeX) + ((double)y - safeY) * (y - safeY));

        return distance <= safeRadius;
    }
}
